Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
The nanoid npm package is a small, secure, URL-friendly, unique string ID generator for JavaScript applications. It is designed to be fast and efficient, producing random or custom ID strings suitable for a variety of applications, including database keys, session identifiers, and more.
Simple ID Generation
Generate a unique, URL-friendly ID. The default ID length is 21 characters, which provides a good balance of speed and uniqueness.
const { nanoid } = require('nanoid');
console.log(nanoid()); // Example output: 'V1StGXR8_Z5jdHi6B-myT'
Custom Length ID Generation
Generate a unique ID with a custom length. This allows for shorter or longer IDs depending on the level of uniqueness required.
const { nanoid } = require('nanoid');
console.log(nanoid(10)); // Example output: 'IRFa-VaY2b'
Non-secure ID Generation
Generate a non-secure ID with a custom alphabet and length. This is useful for cases where unique IDs are needed without the cryptographic strength.
const { customAlphabet } = require('nanoid');
const nanoid = customAlphabet('1234567890abcdef', 10);
console.log(nanoid()); // Example output: '4f90d13a42'
Custom Alphabet ID Generation
Generate a unique ID using a custom alphabet. This is useful when you need to avoid certain characters or use a specific set of characters for IDs.
const { customAlphabet } = require('nanoid');
const alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
const nanoid = customAlphabet(alphabet, 10);
console.log(nanoid()); // Example output: '4f90d13a42'
The uuid package can generate RFC-compliant UUIDs. It offers different versions of UUIDs, such as v1 (timestamp-based), v4 (random), and others. Compared to nanoid, uuid provides more standardized and structured IDs, but they are not as compact as nanoid's IDs.
Shortid is another package for generating short non-sequential url-friendly unique ids. However, it is no longer recommended for use as it has been deprecated in favor of nanoid, which is more secure and maintains a smaller size.
Uniqid is a package that generates unique IDs based on the current time and an optional prefix or suffix. It is less feature-rich compared to nanoid and does not provide the same level of customization or security.
English | Русский | 简体中文 | Bahasa Indonesia
A tiny, secure, URL-friendly, unique string ID generator for JavaScript.
“An amazing level of senseless perfectionism, which is simply impossible not to respect.”
A-Za-z0-9_-
).
So ID size was reduced from 36 to 21 symbols.import { nanoid } from 'nanoid'
model.id = nanoid() //=> "V1StGXR8_Z5jdHi6B-myT"
Supports modern browsers, IE with Babel, Node.js and React Native.
Read full docs here.
FAQs
A tiny (116 bytes), secure URL-friendly unique string ID generator
We found that nanoid demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.